<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      html,
      body {
        width: 100%;
        height: 100%;
      }
      .container {
        height: 100%;
      }
      .content {
        height: 3000px;
      }
      .loading {
        width: 50px;
        height: 50px;
        margin: 0 auto;
        background-color: red;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="content"></div>
      <div class="loading"></div>
    </div>

    <script>
      var intersectionObserver = new IntersectionObserver(function (entries) {
        console.log(entries[0], 'entries')
        // If intersectionRatio is 0, the target is out of view
        // and we do not need to do anything.
        if (entries[0].isIntersecting) {
          console.log('到底部')
        }
        // loadItems(10)
        console.log('Loaded new items')
      })
      // start observing
      intersectionObserver.observe(document.querySelector('.loading'))
    </script>
  </body>
</html>
